package com.cuitrip.business.tripservice.proxy;

import android.text.TextUtils;

import com.cuitrip.business.tripservice.model.FormType;
import com.cuitrip.business.tripservice.model.ServiceInfo;
import com.lab.utils.ArrayUtil;

/**
 * 行程数据代理类
 * Created by ak on 15/9/23.
 */
public class ServiceFormProxy {


    private static ServiceFormProxy sInstance;

    public static ServiceFormProxy getInstance() {
        if (null == sInstance)
            sInstance = new ServiceFormProxy();
        return sInstance;
    }

    public boolean isFormComplete(ServiceInfo serviceInfo, FormType formType) {
        boolean isComplete = false;
        switch (formType) {
            case TITLE:
                isComplete = !TextUtils.isEmpty(serviceInfo.getName());
                break;
            case MAIN_PIC:
                isComplete = !TextUtils.isEmpty(serviceInfo.getBackPic());
                break;
            case PIC:
                isComplete = serviceInfo.getPictureDescriptionList().size() > 2;
                break;
            case ADDRESS:
                isComplete = !TextUtils.isEmpty(serviceInfo.getAddress());
                break;
            case CATEGORY:
                isComplete = !ArrayUtil.isNullOrEmpty(serviceInfo.getCateList());
                break;
            case DESCRIPTION:
                isComplete = !(TextUtils.isEmpty(serviceInfo.getHighLight()) || TextUtils.isEmpty(serviceInfo.getServiceDescript()) || TextUtils.isEmpty(serviceInfo.getServiceStory()));
                break;
            case PAY:
                isComplete = !(TextUtils.isEmpty(serviceInfo.getPriceType()) || TextUtils.isEmpty(serviceInfo.getPrice())
                        || TextUtils.isEmpty(serviceInfo.getFeeInclude()) ||
                        TextUtils.isEmpty(serviceInfo.getFeeExclude()) || TextUtils.isEmpty(serviceInfo.getServiceTime()) || serviceInfo.getMinBuyerNum() == 0 || serviceInfo.getMaxbuyerNum() == 0 || serviceInfo.getPreOrderDays() == 0
                );
                break;
            case OTHERS:
                isComplete = !(TextUtils.isEmpty(serviceInfo.getMeetingPlace()));
                break;
        }
        return isComplete;
    }

    public FormType hasFormInvalidType(ServiceInfo serviceInfo) {
        return hasFormInValidType(serviceInfo, FormType.MAIN_PIC, FormType.PIC, FormType.TITLE, FormType.ADDRESS, FormType.CATEGORY, FormType.DESCRIPTION, FormType.PAY, FormType.OTHERS);
    }

    private FormType hasFormInValidType(ServiceInfo serviceInfo, FormType... formTypes) {
        FormType invalidFormType = FormType.CORRECT;
        for (FormType formType : formTypes) {
            if (!isFormComplete(serviceInfo, formType)) {
                invalidFormType = formType;
                break;
            }
        }
        return invalidFormType;
    }

}
